package org.abratuhi.kvngroupware.widget;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Graphics;
import java.util.Properties;

import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;

import org.abratuhi.kvngroupware.manager.Manager;
import org.abratuhi.kvngroupware.network.MessageSender;

@SuppressWarnings("serial")
public abstract class AbstractUIWidget extends AbstractWidget{
	
	@SuppressWarnings("unchecked")
	protected Manager manager;
	protected Properties locale;
	
	protected JPanel datapanel = new JPanel();
	protected JPanel buttonpanel = new JPanel();
	protected JList datalist = new JList();
	protected JScrollPane datascrollpane = new JScrollPane(datalist);
	
	@SuppressWarnings("unchecked")
	public AbstractUIWidget(String frametitle, MessageSender sender, Properties locale, Manager manager){
		super(frametitle, sender);
		
		this.manager = manager;
		this.locale = locale;
		
		datapanel.setLayout(new BorderLayout());
		datapanel.add(datascrollpane, BorderLayout.CENTER);
		
		setLayout(new BorderLayout());
		setPreferredSize(new Dimension(200,200));
		setVisible(true);
		
		add(datapanel, BorderLayout.CENTER);
		add(buttonpanel, BorderLayout.SOUTH);
	}
	
	public void paint(Graphics g){
		super.paint(g);
		datalist.setListData(manager.getDataForWidget());
	}
	
	public void createWindow(){
		super.createWindow();
		frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
	}

}
